home *** CD-ROM | disk | FTP | other *** search
- property iType, iMin, iMax, iInc, ichField, ichButton, iLastValidValue, iFieldName, iCastNumNormal, iCastNumIncr, iCastNumDecr
-
- on birth me, type, min, max, incAmount, chText, theFieldName
- set iType to type
- set iMin to min
- set iMax to max
- set iInc to incAmount
- set ichField to chText
- set ichButton to ichField + 1
- set iLastValidValue to iMin
- set iFieldName to theFieldName
- mSetValue(me, iLastValidValue)
- return me
- end
-
- on mHit me
- set castNumNormal to the castNum of sprite ichButton
- set iCastNumNormal to castNumNormal
- set iCastNumIncr to castNumNormal + 1
- set iCastNumDecr to castNumNormal + 2
- set iLastValidValue to field the castNum of sprite ichField
- set lowerLimitBeepedFlag to 0
- set upperLimitBeepedFlag to 0
- set mouseDownFlag to 1
- set firstTimeFlag to 1
- repeat while mouseDownFlag
- if rollOver(ichButton) then
- set okToChangeValueFlag to 1
- if the mouseV <= the locV of sprite ichButton then
- set lowerLimitBeepedFlag to 0
- set sign to 1
- if iLastValidValue = iMax then
- set okToChangeValueFlag to 0
- if not upperLimitBeepedFlag then
- beep()
- set upperLimitBeepedFlag to 1
- set the castNum of sprite ichButton to castNumNormal
- updateStage()
- end if
- end if
- else
- set upperLimitBeepedFlag to 0
- set sign to -1
- if iLastValidValue = iMin then
- set okToChangeValueFlag to 0
- if not lowerLimitBeepedFlag then
- beep()
- set lowerLimitBeepedFlag to 1
- set the castNum of sprite ichButton to castNumNormal
- updateStage()
- end if
- end if
- end if
- if okToChangeValueFlag then
- mChangeValue(me, sign)
- end if
- else
- set the castNum of sprite ichButton to castNumNormal
- updateStage()
- end if
- if firstTimeFlag then
- set firstTimeFlag to 0
- wait(15)
- end if
- set mouseDownFlag to the mouseDown
- end repeat
- set the castNum of sprite ichButton to castNumNormal
- updateStage()
- end
-
- on mChangeValue me, sign
- if sign = 1 then
- set the castNum of sprite ichButton to iCastNumIncr
- else
- set the castNum of sprite ichButton to iCastNumDecr
- end if
- updateStage()
- if iType = #int then
- set iLastValidValue to (integer(iLastValidValue / iInc) * iInc) + (iInc * sign)
- else
- if iType = #real then
- set iLastValidValue to (iLastValidValue / iInc * iInc) + (iInc * sign)
- end if
- end if
- put iLastValidValue into field the castNum of sprite ichField
- end
-
- on mGetValue me
- set theTypedInString to the text of field iFieldName
- set newValue to value(theTypedInString)
- if iLastValidValue <> newValue then
- set iLastValidValue to newValue
- end if
- return iLastValidValue
- end
-
- on mSetValue me, theNewValue
- if (theNewValue < iMin) or (theNewValue > iMax) then
- alert("Bad value passed to IncrDecrValue:" && theNewValue)
- return
- end if
- set iLastValidValue to theNewValue
- set the text of field iFieldName to string(iLastValidValue)
- updateStage()
- end
-
- on mValidate me
- set theTypedInString to the text of field iFieldName
- set newValue to value(theTypedInString)
- if voidp(newValue) then
- alert("The value in the " & iFieldName & " field must be numeric")
- mSetValue(me, iMin)
- return 0
- end if
- if (newValue > iMax) or (newValue < iMin) then
- alert("Please enter a value between " & iMin & " and " & iMax & " into the " & iFieldName & " field.")
- mSetValue(me, iMin)
- return 0
- end if
- return 1
- end
-